//! Brief description
/*!
\file Picture.cpp
\author Thomas Pfeiffer
\date 13.11.2012
Detail descr.
*/
#include <string>
#include <iostream>
#include <exception>

#include "Picture.h"
#include "PictureManager.h"
#include "FilledShapeFactory.h"
#include "TranspShapeFactory.h"

void main(){
	PictureManager &manager = PictureManager::getInstance();

	TranspShapeFactory &tfact = TranspShapeFactory::getInstance();
	FilledShapeFactory &ffact = FilledShapeFactory::getInstance();

	// Initialize some pictures
	Picture *pic1 = new Picture("testpic.svg", &tfact);
	Picture *pic2 = new Picture("picture2.svg", &ffact);

	// initialize some values for the pictures
	TPosition pos = { 20, 20 };
	TSize s = {40, 20};
	float radius = (float)5.2;

	// Add a circle and a rectangle to the picture
	pic1->AddCircle(pos, radius, "green");
	pic1->AddRectangle(pos, s, "yellow");

	// add the picture 1 to the manager
	manager.addPicture(pic1);

	// load shapes into the picture manager by the manager
	manager.getPicture("testpic.svg")->LoadShapes("shapes.txt");

	// Load shapes in picture 2
	pic2->LoadShapes("shapes2.txt");

	// add pic 2 to the manager
	manager.addPicture(pic2);

	try
	{
		// try to load a nonexistent shape file
		pic2->LoadShapes("shape_error.txt");
	}
	catch (std::exception & e)
	{
		std::cout << e.what() << std::endl;
	}

	try
	{
		// try to load a faulty shape file
		pic2->LoadShapes("shapesfaulty.txt");
	}
	catch (std::exception & e)
	{
		std::cout << e.what() << std::endl;
	}

	manager.addPicture(new Picture("picture3.svg", &tfact));
	manager.getPicture("picture3.svg")->LoadShapes("shapes.txt");
	manager.getPicture("picture3.svg")->LoadShapes("shapes2.txt");

	// save all pictures managed by the Picturemanager
	manager.SavePictures();
}